package com.wei.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wei.health.model.entity.TBodyInfo;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface TBodyInfoMapper extends BaseMapper<TBodyInfo> {

    @Insert("INSERT INTO t_body_info (creator, nick_name, create_time, updater, update_time, health, "
            + "go_out, work_state, temperature, notice) VALUE "
            + "( #{creator},#{nickName},NOW(),#{updater},NOW(),#{health},#{goOut},"
            + "#{workState},#{temperature},#{notice} )")
    int insertByOne(TBodyInfo bodyInfo);

    @Select("SELECT COUNT(*) FROM t_body_info WHERE creator = #{creator} AND create_time >= CURDATE() AND create_time <= CONCAT(CURDATE(), '23:59:59')")
    int countByOneAsToDay(@Param("creator") int userId);

    List<TBodyInfo> selectByUserId(@Param("creator") int userId, @Param("minDate") Date minDate,
                                   @Param("maxDate") Date maxDate);

    List<TBodyInfo> userRegisList(@Param("minDate") Date minDate,
                                  @Param("maxDate") Date maxDate);

    @Delete("DELETE FROM t_body_info WHERE id = #{id} AND creator = #{creator}")
    int deleteByOne(@Param("id") int id, @Param("creator") int userId);

    @Select("SELECT * FROM t_body_info WHERE id = #{id} AND creator = #{creator}")
    TBodyInfo selectByUserOne(@Param("id") int id, @Param("creator") int userId);

}